var express = require('express');
var router = express.Router();
var userService = require('../../src/service/userService');
var resultMessage = require('../../src/models/resultMessage');

var result = new resultMessage();
var userImpl = new userService();

router.post('/', function (req, res, next) {
    userImpl.checkUser(req.body.usercode, req.body.passcode, function (user) {
        if (user) {
            req.session.user = user;
            res.send(result.ok("登录成功").toString());
        } else
            res.send(result.error("验证失败！").toString());
    });
});
router.post('/logout', function (req, res, next) {
    req.session.user = undefined;
    res.send(result.ok().toString());
});

module.exports = router;
